package gdconf

import (
	"server_cluster/common/logger"
)

// 战斗怪物配置表

type BattleMonsterConfig struct {
	MonsterId        int32 `csv:"Id" gorm:"primary_key;autoIncrement:false"` // 怪物id
	MonsterCodexType int32 `csv:"Pictorialtype,omitempty"`                   // 怪物图鉴类型
}

func (b *BattleMonsterConfig) TableName() string {
	return "config_battle_monster_logic"
}

func (g *GameDataConfig) saveBattleMonsterConfig() {
	saveTableToDb[BattleMonsterConfig](g.Db, readTable[BattleMonsterConfig](g.CsvPathPrefix+"BattleMonster.csv"))
}

func (g *GameDataConfig) loadBattleMonsterConfig() {
	g.GameDataMaps.BattleMonsterConfigMap = make(map[int32]*BattleMonsterConfig)
	for _, battleMonsterConfig := range loadTableFromDb[BattleMonsterConfig](g.Db) {
		g.GameDataMaps.BattleMonsterConfigMap[battleMonsterConfig.MonsterId] = battleMonsterConfig
	}
	logger.Info("BattleMonsterConfig Count: %v", len(g.GameDataMaps.BattleMonsterConfigMap))
}

func GetBattleMonsterConfig(monsterId int32) *BattleMonsterConfig {
	value, exist := CONF.GameDataMaps.BattleMonsterConfigMap[monsterId]
	if !exist {
		logger.Warn("[ConfigNotFound] BattleMonsterConfig, monsterId: %v", monsterId)
		return nil
	}
	return value
}

func GetBattleMonsterConfigMap() map[int32]*BattleMonsterConfig {
	return CONF.GameDataMaps.BattleMonsterConfigMap
}
